<template>
  <a-modal v-model="visible" :width="1080" :title="'优惠券明细 '+title" @ok="batchSelectItem" :footer="null">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="8" :lg="7" :md="8" :sm="24">
            <a-form-item label="用户昵称">
              <a-input placeholder="请输入用户昵称" v-model="queryParam.nickname"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="8" :lg="7" :md="8" :sm="24">
            <a-form-item label="用户手机号">
              <a-input placeholder="请输入手机号" v-model="queryParam.phone"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="8" :lg="7" :md="8" :sm="24">
            <a-form-item label="使用状态">
              <j-dict-select-tag v-model="queryParam.status" placeholder="全部" dictCode="user_coupon_use_status"/>
            </a-form-item>
          </a-col>
          <a-col :xl="8" :lg="7" :md="8" :sm="24">
            <a-form-item label="领取时间">
              <a-range-picker format="YYYY-MM-DD" :placeholder="['开始时间', '结束时间']" @change="onDateChange"/>
            </a-form-item>
          </a-col>
          <a-col :xl="8" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <!-- <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button> -->
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- table区域-begin -->
    <div>

      <a-table ref="table" size="small" bordered rowKey="id" :columns="columns" :dataSource="dataSource"
               :pagination="ipagination" :loading="loading"
               class="j-table-force-nowrap" @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="isUseSlot" slot-scope="text,record">
          <span v-if="record.isUse==1">已使用</span>
          <span v-else-if="record.isExpire==1">已过期</span>
          <span v-else>未使用</span>
        </template>

        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="55px" alt=""
               style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a-popconfirm v-if="record.status==1" title="确定停用吗?" @confirm="() => stopItem(record.id)">
            <a>停用</a>
          </a-popconfirm>
        </span>

      </a-table>
    </div>

  </a-modal>
</template>

<script>
import {getAction} from '@/api/manage'
import '@/assets/less/TableExpand.less'
import {mixinDevice} from '@/utils/mixin'
import {JeecgListMixin} from '@/mixins/MyJeecgListMixin'


export default {
  name: 'MmsCouponMapList',
  mixins: [JeecgListMixin, mixinDevice],
  components: {},
  data() {
    return {
      pageCheckedKeys: [],
      noPageCheckedKeys: [],
      pageCheckedRows: [],
      noPageCheckedRows: [],
      visible: false,
      description: '优惠券明细管理页面',
      title: "",
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: "center",
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          }
        },
        {
          title: '用户昵称',
          align: "center",
          dataIndex: 'nickname'
        },
        {
          title: '手机号',
          align: "center",
          dataIndex: 'phone'
        },
        {
          title: '领取时间',
          align: "center",
          dataIndex: 'createTime',
          customRender: function (text) {
            return !text ? "" : (text.length > 10 ? text.substr(0, 10) : text)
          }
        },
        {
          title: '使用状态',
          align: "center",
          dataIndex: 'isExpire',
          scopedSlots: {customRender: 'isUseSlot'}
        },
        // {
        //   title: '是否已使用：0=未使用，1=已使用',
        //   align: "center",
        //   dataIndex: 'isUse'
        // },
        {
          title: '操作',
          dataIndex: 'action',
          align: "center",
          scopedSlots: {customRender: 'action'}
        }
      ],
      url: {
        list: "/mallPlus/coupon/detailList",
        delete: "/mallPlus/coupon/delete",
        deleteBatch: "/mallPlus/coupon/deleteBatch",
        exportXlsUrl: "/mallPlus/coupon/exportXls",
        importExcelUrl: "mallPlus/coupon/importExcel",

      },
      dictOptions: {},
    }
  },
  created() {
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
  },
  methods: {
    open(couponId, uid, nickname, phone) {
      if (couponId) {
        this.queryParam.couponId = couponId
      }
      if (uid) {
        this.queryParam.uid = uid
      }
      if (nickname) {
        this.queryParam.nickname = nickname
      }
      if (phone) {
        this.queryParam.phone = phone
      }
      this.loadData()
    },
    setSelected() {
      //不能删除
    },
    stopItem(id) {
      getAction("/mallPlus/coupon/stop", {id: id}).then((res) => {
        if (res.success) {
          this.loadData()
        }
      })
    },
    initDictConfig() {
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>
